<template>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="招聘会名称: ">
            <div>{{ applyData.careerTitle }}</div>
            <!-- <el-input v-model="applyData.careerTitle" disabled placeholder="请输入招聘标题" /> -->
        </el-form-item>

        <el-form-item label="举办时间: ">
            <div>{{ parseTime(applyData.meetTime, '{y}年{m}月{d}日') }} - {{ parseTime(applyData.endTime, '{y}年{m}月{d}日')
                }}</div>
        </el-form-item>

        <el-form-item label="参加岗位">
            <el-table :data="companyCareerFairList" style="width: 100%" max-height="250">
                <el-table-column label="岗位名称">
                    <template #default="scope">
                        <el-form-item>
                            <el-select v-model="scope.row.stationIds" :disabled="applyType === 'detail'" multiple
                                filterable allow-create placeholder="请选择岗位名称">
                                <el-option v-for="item in stationList" :key="item.id" :label="item.stationName"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="操作" v-if="!isEdit">
                    <template #default="scope">
                        <el-button type="success" size="mini" plain @click="handldeAddComp">新增</el-button>
                        <el-button v-if="companyCareerFairList.length > 1" type="danger" size="mini" plain
                            @click="handleDelComp(scope.$index)">删除</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
        </el-form-item>

        <el-form-item style="text-align: right;">
            <el-button v-if="applyType === 'apply'" type="primary" @click="handleApplyConfirm">提交审核</el-button>
            <el-button @click="cancel">取 消</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
import { listStation } from "@/api/system/station";
import { getCareerFair, addCareerFairPost } from "@/api/system/careerFair";
export default {
    props: {
        applyData: {
            type: Object,
            required: true
        },
        applyType: {
            type: String,
            required: true
        },
    },
    data() {
        return {
            isEdit: false,
            companyCareerFairList: [{
                id: '',
                compId: '',
                stationIds: []
            },],
            form: {},
            rules: {},
            stationList: []
        };
    },
    created() {
        console.log(this.applyData, this.companyId, 'applyData')


        this.getStationList()
    },
    computed: {
        isCompany() {
            return this.$store.state.user.roles[0] === 'company' && !!this.$store.state.user.userData.compId
        },
        companyId() {
            return this.$store.state.user.userData.compId
        }
    },
    watch: {},
    methods: {
        handldeAddComp() {
            this.companyCareerFairList.push({
                id: '',
                compId: '',
                stationIds: []
            })
        },
        handleDelComp(index) {
            this.companyCareerFairList.splice(index, 1)
        },
        /** 查询公司岗位信息列表 */
        getStationList() {
            listStation({
                pageNum: 1,
                pageSize: 999,
                compId: this.companyId,
            }).then(response => {
                this.stationList = response.rows;
                if (this.applyType === 'detail') {
                    this.getDetailData()
                }
            });
        },
        getDetailData() {
            getCareerFair(String(this.applyData.id)).then(response => {
                // console.log(response, 'response')
                const tempData = response.data.companyStations
                this.companyCareerFairList = [{
                    id: '',
                    compId: '',
                    stationIds: tempData.map(item => item.id)
                }]
                console.log(this.companyCareerFairList, 'response')
            });
        },
        concatParams() {
            this.companyCareerFairList.forEach(item => {
                item.id = this.applyData.id
                item.compId = this.companyId
            })
        },
        handleApplyConfirm() {
            this.concatParams()
            addCareerFairPost(this.companyCareerFairList).then(res => {
                this.$modal.msgSuccess("操作成功");
                this.cancel()
            })
        },
        cancel() {
            this.$emit('cancel')
        }
    },

    mounted() {

    },
    components: {},
}
</script>

<style lang='scss' scoped></style>